var WindDataTableColumns = new Object();

WindDataTableColumns.createConfig = function(dataTable) {
	var config = new Object();

	config.dataTable = dataTable;

	config.type = "dataTableColumn";

	if(dataTable!=null) {
		var filters = new Array();
		var filter = new Object();
		filter.property = "dataTableCode";
		filter.operator = "=";
		filter.value = config.dataTable.code;
		filters[0] = filter;
		config.filters = filters;
	}
	
	config.tableTitle = "Columns";
	config.addTableColumns = function(tableModel) {
		{
			var column = new WindTableColumnModel();
			column.setTitle("Code");
			tableModel.addColumn(column);
		}
		{
			var column = new WindTableColumnModel();
			column.setTitle("Title");
			tableModel.addColumn(column);
		}
		{
			var column = new WindTableColumnModel();
			column.setTitle("Order");
			tableModel.addColumn(column);
		}
	}
	config.addTableRowCellsFromEntity = function(row, entity) {
		row.addCell(entity.code);
		row.addCell(entity.title);
		row.addCell(entity.order);
	}
	config.dialogInsertTitle = "Insert a new data table column";
	config.dialogUpdateTitle = "Update an existing data table column";
	config.configureDialogView = function(dialogView, entity) {
		
		var layout = WindLayout.createView();
		//layout.setWidth("100%");
		dialogView.getBody().addView(layout);
		
		var labelColumnWidth = "50px";
		
		{
			var row = layout.createRowView();
			
			{
				var label = WindLabel.createView();
				label.setText("Code:"); 
				var cell = row.createCellView();
				cell.setWidth(labelColumnWidth);
				cell.addView(label);
			}
			
			dialogView.codeText = WindText.createView();
			if(entity!=null) {
				dialogView.codeText.setValue(entity.code);
			} else {
				dialogView.codeText.setValue("COL_X");
			}
			var cell = row.createCellView();
			cell.addView(dialogView.codeText);
		}
		{
			var row = layout.createRowView();
			
			{
				var label = WindLabel.createView();
				label.setText("Title:"); 
				var cell = row.createCellView();
				cell.addView(label);
			}
			
			dialogView.titleText = WindText.createView();
			if(entity!=null) {
				dialogView.titleText.setValue(entity.title);
			} else {
				dialogView.titleText.setValue("Col X");
			}
			var cell = row.createCellView();
			cell.addView(dialogView.titleText);
		}
		{
			var row = layout.createRowView();
			
			{
				var label = WindLabel.createView();
				label.setText("Order:"); 
				var cell = row.createCellView();
				cell.addView(label);
			}
			
			dialogView.orderText = WindText.createView();
			if(entity!=null) {
				dialogView.orderText.setValue(entity.order);
			} else {
				dialogView.orderText.setValue(1);
			}
			var cell = row.createCellView();
			cell.addView(dialogView.orderText);
		}
	}
	config.fillEntityFromDialog = function(dialogView, entity) {
		entity.code = dialogView.codeText.getValue();
		entity.title = dialogView.titleText.getValue();
		entity.order = dialogView.orderText.getValue();
		entity.dataTableCode = config.dataTable.code;
	}
	
	return config;
}

